/*
 * Copyright (c) [2020-2021] [http://www.zxpnet.com]
 */

package com.zxp.security.service;

import com.zxp.security.model.User;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author zxp
 * @date 2021/7/5 10:33
 */
@Service
@RequiredArgsConstructor
public class MyUserDetailService implements UserDetailsService {
    
    private  final PasswordEncoder passwordEncoder;    
    private final UserServiceI userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userService.findByUsernameOrPhone(username);
        //return new User(username, password, AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_admin,ROLE_USER"));
        return user;
    }
    
}
